package com.ruoyi.project.jiaqin.answerreply.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.jiaqin.answerreply.domain.JiaqinAnswerReply;
import com.ruoyi.project.jiaqin.answerreply.mapper.JiaqinAnswerReplyMapper;
import com.ruoyi.project.jiaqin.answerreply.service.IJiaqinAnswerReplyService;
import com.ruoyi.project.jiaqin.company.domain.Company;
import com.ruoyi.project.jiaqin.company.mapper.CompanyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * 问答评论回复Service业务层处理
 *
 * @author LCL
 * @date 2021-11-19
 */
@Service
public class JiaqinAnswerReplyServiceImpl implements IJiaqinAnswerReplyService
{
    @Autowired
    private JiaqinAnswerReplyMapper jiaqinAnswerReplyMapper;

    /**
     * 查询问答评论回复
     *
     * @param id 问答评论回复ID
     * @return 问答评论回复
     */
    @Override
    public JiaqinAnswerReply selectJiaqinAnswerReplyById(String id)
    {
        return jiaqinAnswerReplyMapper.selectJiaqinAnswerReplyById(id);
    }

    /**
     * 查询问答评论回复列表
     *
     * @param jiaqinAnswerReply 问答评论回复
     * @return 问答评论回复
     */
    @Override
    public List<JiaqinAnswerReply> selectJiaqinAnswerReplyList(JiaqinAnswerReply jiaqinAnswerReply)
    {
        return jiaqinAnswerReplyMapper.selectJiaqinAnswerReplyList(jiaqinAnswerReply);
    }

    /**
     * 新增问答评论回复
     *
     * @param jiaqinAnswerReply 问答评论回复
     * @return 结果
     */
    @Override
    public int insertJiaqinAnswerReply(JiaqinAnswerReply jiaqinAnswerReply)
    {
        jiaqinAnswerReply.setId(UUID.randomUUID().toString().replace("-",""));
        return jiaqinAnswerReplyMapper.insertJiaqinAnswerReply(jiaqinAnswerReply);
    }

    /**
     * 修改问答评论回复
     *
     * @param jiaqinAnswerReply 问答评论回复
     * @return 结果
     */
    @Override
    public int updateJiaqinAnswerReply(JiaqinAnswerReply jiaqinAnswerReply)
    {
        return jiaqinAnswerReplyMapper.updateJiaqinAnswerReply(jiaqinAnswerReply);
    }

    /**
     * 删除问答评论回复对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteJiaqinAnswerReplyByIds(String ids)
    {
        return jiaqinAnswerReplyMapper.deleteJiaqinAnswerReplyByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除问答评论回复信息
     *
     * @param id 问答评论回复ID
     * @return 结果
     */
    @Override
    public int deleteJiaqinAnswerReplyById(String id)
    {
        return jiaqinAnswerReplyMapper.deleteJiaqinAnswerReplyById(id);
    }

    @Autowired
    private CompanyMapper companyMapper;
    @Override
    public PageInfo<JiaqinAnswerReply> selectAnswerReplyListByCommentId(Integer pageNum, Integer pageSize, String questionAnswerId) {
        JiaqinAnswerReply answerReply = new JiaqinAnswerReply();
        answerReply.setQuestionAnswerId(questionAnswerId);
        PageHelper.startPage(pageNum,pageSize);
        List<JiaqinAnswerReply> list = jiaqinAnswerReplyMapper.selectJiaqinAnswerReplyList(answerReply);
        for (JiaqinAnswerReply JAR : list) {
            Company company = companyMapper.selectCompanyByMemberId(JAR.getFromUserId());
            if (company != null) {
                JAR.setIsCompany(1);
            } else {
                JAR.setIsCompany(0);
            }
        }
        PageInfo<JiaqinAnswerReply> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
